<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring容器深度解析：BeanFactory vs ApplicationContext</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .code-tag {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 2px 8px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
            font-size: 0.9em;
            display: inline-block;
            margin: 0 4px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            color: #667eea;
        }
        
        .section-divider {
            width: 80px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            margin: 2rem auto;
            border-radius: 2px;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .image-container {
            position: relative;
            overflow: hidden;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            margin: 2rem 0;
        }
        
        .image-container img {
            width: 100%;
            height: auto;
            display: block;
            transition: transform 0.3s ease;
        }
        
        .image-container:hover img {
            transform: scale(1.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl font-bold mb-6">Spring容器深度解析</h1>
            <h2 class="text-3xl font-light mb-8">BeanFactory vs ApplicationContext</h2>
            <p class="text-xl max-w-3xl mx-auto opacity-90">
                深入理解Spring框架的两大核心容器，掌握它们的本质区别与应用场景
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Spring框架的世界里，<span class="code-tag">BeanFactory</span>和<span class="code-tag">ApplicationContext</span>是两个最核心的概念。它们都是用于管理Bean对象的容器，但在功能、性能和使用场景上存在着显著的差异。理解这些差异，对于构建高效的Spring应用至关重要。
            </p>
        </div>

        <!-- Core Differences Section -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-center mb-12 text-gradient">核心差异解析</h2>
            
            <!-- Difference Cards Grid -->
            <div class="grid md:grid-cols-2 gap-8">
                <!-- 功能差异 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">功能差异</h3>
                    <div class="space-y-4 text-gray-600">
                        <div class="pl-4 border-l-4 border-purple-400">
                            <p><strong>BeanFactory：</strong>Spring最基础的容器接口，提供基本的Bean管理功能，包括实例化、依赖注入和生命周期管理。</p>
                        </div>
                        <div class="pl-4 border-l-4 border-pink-400">
                            <p><strong>ApplicationContext：</strong>BeanFactory的超集，扩展了更多企业级特性，如国际化支持、事件传播、AOP集成等。</p>
                        </div>
                    </div>
                </div>

                <!-- 加载策略 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-rocket"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">加载策略</h3>
                    <div class="space-y-4 text-gray-600">
                        <div class="pl-4 border-l-4 border-purple-400">
                            <p><strong>BeanFactory：</strong>采用延迟加载策略，只有在请求获取Bean时才进行实例化，启动速度快但首次访问慢。</p>
                        </div>
                        <div class="pl-4 border-l-4 border-pink-400">
                            <p><strong>ApplicationContext：</strong>采用预实例化策略，容器启动时就实例化所有单例Bean，启动慢但运行时性能好。</p>
                        </div>
                    </div>
                </div>

                <!-- 配置加载 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-file-code"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">配置加载</h3>
                    <div class="space-y-4 text-gray-600">
                        <div class="pl-4 border-l-4 border-purple-400">
                            <p><strong>BeanFactory：</strong>需要手动指定配置文件位置或注解扫描路径，使用XmlBeanFactory等具体实现。</p>
                        </div>
                        <div class="pl-4 border-l-4 border-pink-400">
                            <p><strong>ApplicationContext：</strong>自动扫描并加载所有符合条件的Bean定义，使用ClassPathXmlApplicationContext等实现。</p>
                        </div>
                    </div>
                </div>

                <!-- 资源管理 -->
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="feature-icon">
                        <i class="fas fa-recycle"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">资源管理</h3>
                    <div class="space-y-4 text-gray-600">
                        <div class="pl-4 border-l-4 border-purple-400">
                            <p><strong>BeanFactory：</strong>Bean对象由JVM垃圾回收器管理，不再使用时由JVM自动回收。</p>
                        </div>
                        <div class="pl-4 border-l-4 border-pink-400">
                            <p><strong>ApplicationContext：</strong>容器关闭时自动销毁所有单例Bean，主动释放资源，更加可控。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Extension Features -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-center mb-12 text-gradient">扩展特性对比</h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-10">
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="text-center">
                        <h3 class="text-2xl font-bold mb-6 text-purple-600">ApplicationContext 独有特性</h3>
                        <div class="space-y-4">
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-globe text-purple-500 text-xl"></i>
                                <span class="text-lg">MessageSource 国际化支持</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-broadcast-tower text-purple-500 text-xl"></i>
                                <span class="text-lg">ApplicationEventPublisher 事件传播</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-magic text-purple-500 text-xl"></i>
                                <span class="text-lg">AOP 面向切面编程集成</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-folder-open text-purple-500 text-xl"></i>
                                <span class="text-lg">ResourceLoader 资源加载</span>
                            </div>
                        </div>
                    </div>
                    
                    <div class="text-center">
                        <h3 class="text-2xl font-bold mb-6 text-pink-600">BeanFactory 基础功能</h3>
                        <div class="space-y-4">
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-cube text-pink-500 text-xl"></i>
                                <span class="text-lg">Bean 实例化管理</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-link text-pink-500 text-xl"></i>
                                <span class="text-lg">依赖注入</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-sync text-pink-500 text-xl"></i>
                                <span class="text-lg">生命周期管理</span>
                            </div>
                            <div class="flex items-center justify-center space-x-3">
                                <i class="fas fa-memory text-pink-500 text-xl"></i>
                                <span class="text-lg">轻量级实现</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Architecture Visualization -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-center mb-12 text-gradient">架构关系图</h2>
            
            <div class="bg-white rounded-2xl shadow-xl p-10">
                <div class="mermaid">
                    graph TD
                        A[BeanFactory] -->|继承| B[ApplicationContext]
                        A --> C[基础Bean管理]
                        A --> D[延迟加载]
                        A --> E[轻量级容器]
                        
                        B --> F[预实例化]
                        B --> G[事件机制]
                        B --> H[国际化]
                        B --> I[AOP集成]
                        B --> J[资源加载]
                        
                        B --> K[ClassPathXmlApplicationContext]
                        B --> L[FileSystemXmlApplicationContext]
                        B --> M[AnnotationConfigApplicationContext]
                        
                        style A fill:#f093fb,stroke:#f5576c,stroke-width:2px
                        style B fill:#667eea,stroke:#764ba2,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- Class Structure Images -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-center mb-12 text-gradient">类结构详解</h2>
            
            <div class="space-y-8">
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2021/png/21449790/1635990383829-538bc241-e8d2-4f3b-94e8-b526b8685281.png" alt="BeanFactory类结构图">
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark